package com.starbaba.loanUnionLoginStat.view;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import org.apache.struts2.util.StrutsUtil;

import com.base.common.log.LogService;
import com.opensymphony.xwork2.ActionSupport;
import com.starbaba.core.utils.PropertyParamMapBuilder;
import com.starbaba.core.utils.Struts2Utils;
import com.starbaba.core.utils.json.JsonUtils;
import com.starbaba.core.web.page.PageRequest;
import com.starbaba.core.web.page.PageResponse;
import com.starbaba.core.web.struts2.BaseAction;
import com.starbaba.loanUnionLoginStat.model.LoanUnionLoginStatModel;
import com.starbaba.loanUnionLoginStat.service.LoanUnionLoginStatService;
import com.starbaba.loanUnionLoginStat.service.impl.LoanUnionLoginStatServieImpl;
import com.starbaba.outsideapi.model.OutSideApiEntity;

/**
 * 联登统计
 * @author Administrator
 *
 */
public class LoanUnionLoginStatAction extends BaseAction {
	
	private static final long serialVersionUID = 1L;
	
	LoanUnionLoginStatService service=new LoanUnionLoginStatServieImpl();
	
	private String page;
	private String ck_module;
	private String position;
	
	private String fileName;
	private InputStream input;
	
	public String getFileName() {
		return fileName;
	}

	public InputStream getInput() {
		return input;
	}

	public String showPage(){
		paramsMap=PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		service.showPage(paramsMap);
		return ActionSupport.SUCCESS;
	}
	
	
	//联登统计列表
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public void getStatList(){
		paramsMap=PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		paramsMap.put("page", page);
		paramsMap.put("ck_module", ck_module);
		paramsMap.put("position", position);
		parsePageRequest();
		PageResponse pageResponse = new PageResponse();
		try {
			List<LoanUnionLoginStatModel> list = service.getStatList(pageRequest, pageResponse, paramsMap);
			pageResponse.setAaData(list);
			pageResponse.setSEcho(pageRequest.getSEcho());
		} catch (Exception e) {
			LogService.error("联登统计统计列表出错",e);
			e.printStackTrace();
		}
		
		try {
			sendJsonMessage(JsonUtils.toJson(pageResponse, null, true, null, false));
		} catch (IOException e) {
			LogService.error(e);
		}
	}

	
	public String  exportList(){
		paramsMap=PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		parsePageRequest();
		PageResponse pageResponse = new PageResponse();
		try {
			pageRequest.setIDisplayStart(-1);
			pageRequest.setIDisplayLength(-1);
			List<LoanUnionLoginStatModel> list = service.getStatList(pageRequest, pageResponse, paramsMap);
			String value = service.exportDetailCVS(list);
			input = new ByteArrayInputStream(value.getBytes("GBK"));
			fileName = System.currentTimeMillis() + ".csv";
		} catch (Exception e) {
		LogService.error(e);
		}
		return ActionSupport.SUCCESS;
	}
	
	
	
	
	public void setPage(String page) {
		this.page = page;
	}

	public void setCk_module(String ck_module) {
		this.ck_module = ck_module;
	}

	public void setPosition(String position) {
		this.position = position;
	}
	
}
